<?php
//面板查看 统计功能
//模块名_控制名
class Order_StatisticsController extends Zend_Controller_Action
{
	public function preDispatch(){
		$this->tplDirectory = "order/statistics/";
	}
	
	public function indexAction(){
		$otClassArr = Order_Service_OrderStatistics::$otClassArr;
		$this->view->otClass = $otClassArr;
		echo Cff::renderTpl($this->tplDirectory.'index.tpl',"layout");		
	}
		
	public function listAction(){
		$page = $this->_request->getParam('page',1);
		$pageSize = $this->_request->getParam('pageSize',20);
		$loginId = $this->_request->getParam('login_id','');
		$otClass = $this->_request->getParam('ot_class',''); 
		$dateFrom = $this->_request->getParam('dateFrom','');
		$dateTo = $this->_request->getParam('dateTo','');
		
		$cond =array(); 
		$dateFrom && $cond['dateFrom'] = $dateFrom;
		$dateTo && $cond['dateTo'] = $dateTo;
		if(!empty($loginId)){
			$userInfo = User_Service_User::getByLoginId($loginId);			
			if($userInfo['user_id']){
				$cond['user_id'] = $userInfo['user_id'];
			}else{
				$cond['user_id'] = $loginId;
			}
		}
		if($otClass !== ''){
			$cond['ot_class'] = $otClass;
		}
		
		$data=array('total'=>0,'ask'=>0);
		$orderby = array('ot_date desc');
		$total = Order_Service_OrderStatistics::getByCond($cond,'count(*)',0,0);
		$rows = Order_Service_OrderStatistics::getByCond($cond,'*',$pageSize,$page,$orderby);
		
		$otClassArr = Order_Service_OrderStatistics::$otClassArr;
		foreach ($rows as $key => $val){
			$tmpInfo = User_Service_User::getByUserId($val['user_id']);
			$rows[$key]['login_id'] = $tmpInfo['login_id'];
			$rows[$key]['classText'] = $otClassArr[$val['ot_class']];
		}
		if(!empty($total)){
			$data=array(
				'total'=>$total,
				'result'=>$rows,
				'ask'=>1
			);
		}
			
		die(Zend_Json::encode($data));
	}
	
	public function testarrayAction(){
		$obj = new Order_Service_StatisticsProccess();
		$cond = $row = array();
		$row['ot_order_cnt'] = 60;
		$row['ot_sku_cnt'] = 20;

		$cond['ot_class'] = 3;
		$cond['ot_date'] = '2012-06-14 06:07:08';
		$res = $obj->statisticsEdit($row,$cond);
		var_dump($res);
	}
	

	
}